package com.megoc.menu.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.megoc.menu.R;
import com.megoc.menu.model.BaseList;

import java.util.List;

/**
 * Created by Megoc on 2015/10/15.
 */
public class MenuPersonGridViewAdapter extends BaseAdapter{

    private List<BaseList> listBases;
    private Context context;

    public MenuPersonGridViewAdapter(List<BaseList> listBases, Context context) {
        this.listBases = listBases;
        this.context = context;
    }

    @Override
    public int getCount() {
        return listBases.size();
    }

    @Override
    public Object getItem(int position) {
        return listBases.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder viewHolder;
        if (convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.item_menu_album_gridview,null);
            viewHolder=new ViewHolder();
            viewHolder.simpleDraweeView= (SimpleDraweeView) convertView.findViewById(R.id.view_gridview_img);
            viewHolder.textView= (TextView) convertView.findViewById(R.id.view_gridview_text);
            viewHolder.recipiceView= (TextView) convertView.findViewById(R.id.view_gridview_recipe_text);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        BaseList listBase=listBases.get(position);
        Uri uri=Uri.parse(listBase.getImg());
        viewHolder.simpleDraweeView.setImageURI(uri);
        viewHolder.textView.setText(listBase.getTitle());
        //viewHolder.recipiceView.setText(listBase.getRecipe());
        return convertView;
    }
    class ViewHolder{
        SimpleDraweeView simpleDraweeView;
        TextView textView;
        TextView recipiceView;
    }
}
